package com.clz.appdesign.appdependence.base.mvp;


import com.clz.appdesign.appdependence.base.BaseActivity;

/**
 * @author clz
 * @desc 初始化P，并且连接V，在onDestroy()生命周期中释放P中引用的V。
 */
public abstract class MvpActivity<V, P extends BasePresenter<V>> extends BaseActivity implements BaseView{
    protected P mPresenter;

    @Override
    protected void beforeInit() {
        super.beforeInit();
        this.mPresenter = initPresenter();
        mPresenter.attach((V) this);
    }


    @Override
    protected void onDestroy() {
        mPresenter.detach();
        super.onDestroy();
    }

    @Override
    public void showLoading() {
        show2Loading();
    }

    @Override
    public void hideLoading() {
        hide2Loading();
    }

    /**
     * 初始化presenter
     *
     * @return
     */
    public abstract P initPresenter();
}
